package com.ja.openchat.viewmodels;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.ja.openchat.ui.me.ExpressionStoreDetailFragment;
import com.zy.openchat.core.model.user.UserInfo;

import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class ExpressionStoreItemViewModel extends MultiItemViewModel<ExpressionStoreViewModel> {
    public ObservableField<String> entity = new ObservableField<>();
    public ObservableField<String> typeDes = new ObservableField<>("添加");
    public ObservableField<Integer> type = new ObservableField<>(1);

    public ObservableField<UserInfo> userAvatar = new ObservableField<>(UserInfo.getUserInfo());

    public ExpressionStoreItemViewModel(@NonNull ExpressionStoreViewModel viewModel, String entity, int type) {
        super(viewModel);
        this.type.set(type);
        if (type == 1) {
            this.typeDes.set("添加");
        } else {
            this.typeDes.set("移除");
        }
        this.entity.set(entity);
    }

    /**
     * 获取position的方式有很多种,indexOf是其中一种，常见的还有在Adapter中、ItemBinding.of回调里
     *
     * @return
     */
    public int getPosition() {
        return viewModel.getItemPosition(this);
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putInt("type", type.get());
            viewModel.startContainerActivity(ExpressionStoreDetailFragment.class.getCanonicalName(), bundle);
        }
    });
    //条目的长按事件
    public BindingCommand itemLongClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
        }
    });
}
